#include "stdafx.h"

ANSITextFileWriter::ANSITextFileWriter(const wstring& fileName)
{
	m_good = true;

	_wfopen_s( &m_file, fileName.c_str(), L"wt+" );

	if (m_file == NULL)
	{
		wprintf(L"fopen failed!\n");
		m_good = false;
	}
}

ANSITextFileWriter::~ANSITextFileWriter()
{
	fclose(m_file);
}

void ANSITextFileWriter::write(const string& str)
{
	if ( fwrite(str.c_str(), sizeof(char), str.size(), m_file) != str.size())
	{
		printf("fwrite failed!\n");
		m_good = false;
	}
}

void ANSITextFileWriter::writeLine(const string& str)
{
	string tmp(str);
	tmp.append("\n");
	if ( fwrite(tmp.c_str(), sizeof(char), tmp.size(), m_file) != tmp.size())
	{
		printf("fwrite failed!\n");
		m_good = false;
	}
}

bool ANSITextFileWriter::good()
{
	return m_good;
}